package cn.edu.hit.core.combine;

import cn.edu.hit.core.transfer.Transfer;
import cn.edu.hit.core.transfer.TransferLoader;
import cn.edu.hit.core.Document;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * Map   普通映射  List<Object> --> Object
 * 如：[[55.59439564327069],[83.8979041722205],[37.28872212923427],[25.117321026634155]]   count(*)
 * 生成  [1,1,1,1]
 */
public final class MapperAdapter extends CombineAdapterHelper {
    @Override
    public boolean accept(String type) {
        return "map".equalsIgnoreCase(type);
    }

    @Override
    protected Object combineAndCalculate(List<Document> channelDocs, Document configure, String method, Map<String, Object> arg) {
        List<Object> channelValues = channelDocs.stream()
                .map(doc -> doc.get(VALUE))
                .collect(Collectors.toList());
        Transfer transfer = TransferLoader.get(method);
        return transfer.transfer(channelValues, configure);
    }

}
